package cn.xd.itstack.springframework.utils;

/**
 * @Classname ClassUtil
 * @Description TODO
 * @Date 2022/5/16 下午3:20
 * @Created by lvxiaodong
 */
public class ClassUtil {


    public static ClassLoader getClassLoader() {
        ClassLoader classLoader = null;
        try {
            classLoader = Thread.currentThread().getContextClassLoader();
            return classLoader;
        }catch (Exception e){

        }
        if(classLoader==null){
            classLoader = ClassUtil.class.getClassLoader();
        }
        return classLoader;
    }

    /**
     * Check whether the specified class is a CGLIB-generated class.
     * @param clazz the class to check
     */
    public static boolean isCglibProxyClass(Class<?> clazz) {
        return (clazz != null && isCglibProxyClassName(clazz.getName()));
    }

    /**
     * Check whether the specified class name is a CGLIB-generated class.
     * @param className the class name to check
     */
    public static boolean isCglibProxyClassName(String className) {
        return (className != null && className.contains("$$"));
    }
}
